"""
File: base_api.py
Author: ershixiong
Date: 2023/12/25
describe:

"""
import requests

from hogwarts.WeworkApi.utils.log_utils import logger


class BaseApi:

    @classmethod
    def send(cls, kwargs):
        """
        :param kwargs:
                pay_load = {
                'method': 'post',
                'url': url,
                'params': params,
                'json': data

        }
        :return:
        """
        from hogwarts.WeworkApi.apis.wework import Wework
        # 判断是否为登录接口
        if not kwargs['url'] == 'gettoken':
            # 判断params是否为空,添加token
            if kwargs.get('params'):
                kwargs['params'].update({"access_token": Wework.ACCESS_TOKEN})
            else:
                kwargs['params'] = {"access_token": Wework.ACCESS_TOKEN}

        # 拼接url
        kwargs['url'] = f'{Wework.BASE_URL}{kwargs.get("url")}'
        logger.info(f"请求地址为：{kwargs.get('url')}")

        res = requests.request(**kwargs)
        return res
